package com.dream.technology.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.dream.technology.db.entity.RcRuleCollectionItem;
import com.dream.technology.db.entity.RcRuleCollectionItemQuery;
import com.dream.technology.data.GenericRspDTO;
import com.dream.technology.service.RcRuleCollectionItemService;
import com.dream.technology.vo.ErrorCode;
import io.swagger.annotations.Api;
import org.omg.CORBA.OBJ_ADAPTER;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("风控规则集分类")
@RestController
@RequestMapping("/risk/admin/collection_item")
public class RcRuleCollectionItemController {

    private static final Logger logger = LoggerFactory.getLogger(RcRuleCollectionItemController.class);

    @Autowired
    RcRuleCollectionItemService rcRuleCollectionItemService;

    /**
     * 风控规则集分类接口
     * @param pageNum
     * @param pageSize
     * @param ruleCollectionCode
     * @param ruleCollectionName
     * @return
     */
    @GetMapping("/list")
    public GenericRspDTO<Object> getList(Integer pageNum, Integer pageSize, String ruleCollectionCode, String ruleCollectionName) {

        RcRuleCollectionItemQuery rcRuleCollectionItemQuery =new RcRuleCollectionItemQuery();
        PageHelper.startPage(pageNum,pageSize);
        List<RcRuleCollectionItem> rcRuleCollectionItemList = rcRuleCollectionItemService.selectByExample(rcRuleCollectionItemQuery);
        PageInfo pageInfo=new PageInfo(rcRuleCollectionItemList);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), pageInfo);
    }

    /**
     * 风控规则集分类回显接口
     * @param id
     * @return
     */
    @GetMapping("/id")
    public GenericRspDTO<Object> getById(Long id){

        RcRuleCollectionItem rcRuleCollectionItem = rcRuleCollectionItemService.selectByPrimaryKey(id);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), rcRuleCollectionItem);
    }

    /**
     * 添加规则集配置
     * @param rcRuleCollectionItem
     * @return
     */
    @PostMapping("/add")
    public GenericRspDTO<Object> add(RcRuleCollectionItem rcRuleCollectionItem){

        rcRuleCollectionItemService.insert(rcRuleCollectionItem);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);
    }

    /**
     * 修改规则集配置
     * @param rcRuleCollectionItem
     * @return
     */
    @PostMapping("/update")
    public GenericRspDTO<Object> update(RcRuleCollectionItem rcRuleCollectionItem){

        rcRuleCollectionItemService.updateByPrimaryKeySelective(rcRuleCollectionItem);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);
    }

    /**
     * 删除规则集配置 (逻辑删除)
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public GenericRspDTO<Object> delete(Long id){

        rcRuleCollectionItemService.deleteByPrimaryKey(id);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);
    }
}
